e = Enumerator.new do |y|
	y << 1
	y << 2
	y << 3
end

p e.to_a

e = Enumerator.new do |y|
	(1..3).each {|i| y << i }
end
p e.to_a
a = [1,2,3,4,5]
e = Enumerator.new do |y|
	total = 0
	until a.empty?
		total += a.pop
		y << total
 	end
end
p e.take(2)
p e.to_a
# 附加枚举器
str = "xyz"
enum = str.enum_for(:each_byte)
enum.each { |b| puts b}

# 散列的each
h = { "cat" => "feline", "dog" => "canine", "cow" => "bovine"}
p h.select {|key,value| key =~ /c/}
# 枚举器与select挂钩
e = h.enum_for(:select)
p e.each {|key,value| key=~ /c/}
# 枚举器与each挂钩,枚举器的特点，未覆盖现象
e = h.to_enum
p e.each { }
p e.select {|key,value| key =~ /c/}
